

import javax.microedition.lcdui.*;

public class Login extends Form implements CommandListener, ItemCommandListener {

private TextField name;
private TextField pass;
private Command signin;
private Command signup;
private Command exit;
private StringItem item1;
private StringItem item2;
private MainMidlet midlet;



public Login() {
super("Dang nhap");
name = new TextField("Tai khoan: ", null, 20, TextField.ANY);
pass = new TextField("Mat khau: ", null, 20, TextField.PASSWORD);
signin = new Command("Chon", Command.ITEM, 0);
signup = new Command("Chon", Command.ITEM, 0);
exit = new Command("Thoat", Command.BACK, 1);
item1 = new StringItem(null, "Dang nhap", Item.BUTTON);
item2 = new StringItem(null, "Dang ki", Item.BUTTON);
item1.setDefaultCommand(signin);
item2.setDefaultCommand(signup);
item1.setItemCommandListener(this);
item2.setItemCommandListener(this);
this.append(name);
this.append(pass);
this.append(item1);
this.append(item2);
this.addCommand(exit);
this.setCommandListener(this);
item1.setItemCommandListener(this);
item1.setItemCommandListener(this);
this.midlet = midlet;


}

public void TestInfo(String name, String password) {
     if (name.equals("1") && password.equals("1")) {
       SetDisplay.setCurrent(SetDisplay.MAINCANVAS);
     } else {
       SetDisplay.setCurrent(SetDisplay.ERROR);
     }
}
     
     

public void commandAction(Command c, Displayable d) {


if (c == exit) {
    
  midlet.destroyApp(true);
  midlet.notifyDestroyed();

  }




}







    public void commandAction(Command c, Item item) {
       if (c == signin) {
            TestInfo(name.getString(), pass.getString());
        }
       
        else if (c == signup) {
            SetDisplay.setCurrent(SetDisplay.REGISTER);
        }
}
}
